<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('新增菜单')" />
	<style type="text/css">
		.layui-input, .layui-textarea{width: 87%;}
		.layui-form-label{width:180px}
		.layui-form-select dl{margin-left:12%;min-width: 80%;}
		.layui-edge{margin-right: 7%}
	</style>
</head>
<body>
<form class="layui-form" id="form-menu-add" style="padding: 16px 84px 16px 25px;">
	<input type="hidden" id="guid" name="guid"  th:value="${menuInfo?.guid}">
	<input type="hidden" id="pguidhide" th:value="${menuInfo?.pguid}">
	<div class="layui-form-item">
	<label class="layui-form-label">上级菜单：</label>
	<div class="layui-input-block">
		<select id="pguid" name="pguid" type="select" class='field-ptype' lay-verify="required" lay-search>
			<option value="0">无</option>
		</select>
	</div>
	</div>
	<div class="layui-form-item">
	<label class="layui-form-label">菜单名称：</label>
	<div class="layui-input-block">
		<input type="text" name="menuCaption" id="menuCaption" th:value="${menuInfo?.menuCaption}" lay-verify="required" autocomplete="off" placeholder="请输入" class="layui-input">
	</div>
	</div>
	<div class="layui-form-item">
	<label class="layui-form-label">菜单排序：</label>
	<div class="layui-input-block">
		<input type="text" name="menuOrder" id="menuOrder" th:value="${menuInfo?.menuOrder}" lay-verify="required" autocomplete="off" placeholder="请输入" class="layui-input">
	</div>
	</div>
	<div class="layui-form-item layui-form-text">
	<label class="layui-form-label">菜单状态：</label>
	<div class="layui-input-block">
		<input type="radio" name="menuState" value="1" title="显示" checked>
		<input type="radio" name="menuState" value="0" title="隐藏" th:checked="${menuInfo?.menuState== '0'}? true : false">
	</div>
	</div>
	<div class="layui-form-item">
	<label class="layui-form-label">菜单类型：</label>
	<div class="layui-input-block">
		<input type="radio" name="menuType" value="1" title="目录" checked>
		<input type="radio" name="menuType" value="2" title="菜单" th:checked="${menuInfo?.menuType== '2'}? true : false">
	</div>
	</div>
	<div class="layui-form-item">
	<label class="layui-form-label">菜单访问路径：</label>
	<div class="layui-input-block">
		<input type="text" name="menuUrl" id="menuUrl" th:value="${menuInfo?.menuUrl}" lay-verify="required" autocomplete="off" placeholder="请输入" class="layui-input">
	</div>
	</div>
	<div class="layui-form-item">
	<label class="layui-form-label">菜单图标：</label>
	<div class="layui-input-block">
	<input type="text" name="menuICON" id="menuICON" th:value="${menuInfo?.menuICON}" lay-verify="required" autocomplete="off" placeholder="选择图标" class="layui-input">
	<div style="width: 87%;margin-left: 7%">
		<div id="icondiv" style="display: none;max-height:200px;overflow-y:auto">
			<div data-th-include="system/menu/menu_icon"></div>
		</div>
	</div>
	</div>
	</div>
</form>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
	/*<![CDATA[*/
	var prefix = ctx + "system/menu";
	/*]]>*/
</script>
<script>
var $,layer,form,table;
layui.use(['table','form','layer','jquery'], function () {
	$ = layui.$,layer = layui.layer,form = layui.form,table = layui.table;
	//加载上级菜单下拉框
	$.ajax({
		url: prefix+"/list",
		type: 'get',
		cache: false,
		dataType: 'json',
		success: function(data) {
			var datas = data.data;
			for (var i = 0; i < datas.length; i++) {
				// if(datas[i].pguid==0){
					$('#pguid').append(new Option(datas[i].menuCaption,datas[i].guid))
				// }
			}
			form.render();
			$("#pguid").val(window.location.href.split("=")[1]);
			if($('#pguidhide').val()){
				$("#pguid").val($('#pguidhide').val());
			}
			form.render();
		}
	});
});
//图标块的显示隐藏
$(function() {
	$("input[name='menuICON']").focus(function() {
		$("#icondiv").show();
	});
	$("#icondiv").find(".ico-list i").on("click", function() {
		$('#menuICON').val($(this).attr('class'));
		$("#icondiv").hide();
	});
});
//提交调用的方法
function submitHandler() {
	if($('#guid').val()){//通过判断guid是否存在来判断是新增还是保存
		if ($.validate.form()) {
			$.operate.save(prefix + "/editpost", {'menuInfoItems':JSON.stringify([$.common.formToJSON('form-menu-add')])});
		}
	}else{
		if ($.validate.form()) {
			$.operate.save(prefix + "/addpost", {'menuInfoItems':JSON.stringify([$.common.formToJSON('form-menu-add')])});
		}
	}
}
</script>
</body>
</html>
